<script type="text/javascript" src="paging.js"></script>
<?php
	PhanQuyenNghiepVu();
	if(isset($_GET['mlh']) && trim($_GET['mlh']) != '')
	{
		include_once '../classes/khoahoc_bs.php';
		include_once '../classes/lophoc_bs.php';
		include_once '../classes/chuongtrinhhoc_bs.php';
		include_once '../classes/thoigianhoc_bs.php';
		include_once '../classes/hopdong_bs.php';
		include_once '../classes/giaovienvaitro_bs.php';
		include_once '../classes/giaovien_bs.php';
		include_once '../classes/hocvien_bs.php';
		include_once '../classes/buoihoc_bs.php';
		include_once '../classes/diemdanh_bs.php';
		
		$MaLopHoc = strtoupper(trim($_GET['mlh']));
		$LopHoc = new lophoc_bs();
		$LopHoc->SetMaLopHoc($MaLopHoc);
		$DLopHoc = $LopHoc->LayDanhSach();
		
		$KhoaHoc = new khoahoc_bs();
		$KhoaHoc->SetMaKhoaHoc($DLopHoc[0]['MaKhoaHoc']);
		$DKhoaHoc = $KhoaHoc->LayDanhSach();
		$TenKhoa = $DKhoaHoc[0]['TenKhoaHoc'];
		
		$PhongHoc = new phonghoc_bs();
		$PhongHoc->SetMaPhong($DLopHoc[0]['MaPhong']);
		$DPhongHoc = $PhongHoc->LayDanhSach();
		$TenPhong = $DPhongHoc[0]['TenPhong'];
		
		$ChuongTrinhHoc = new chuongtrinhhoc_bs();
		$ChuongTrinhHoc->SetMaChuongTrinh($DLopHoc[0]['MaChuongTrinh']);
		$DChuongTrinhHoc = $ChuongTrinhHoc->LayDanhSach();
		$TenChuongTrinh = $DChuongTrinhHoc[0]['TenChuongTrinh'] . ' - ' . $DChuongTrinhHoc[0]['SoTiet'] . ' tiết';
		
		$ThoiGianHoc = new thoigianhoc_bs();
		$ThoiGianHoc->SetMaThoiGianHoc($DLopHoc[0]['MaThoiGianHoc']);
		$DThoiGianHoc = $ThoiGianHoc->LayDanhSach();
		$TenThoiGian = $DThoiGianHoc[0]['ChuThich'];
		
		$BuoiHoc = new buoihoc_bs();
		$BuoiHoc->SetMaLopHoc($DLopHoc[0]['MaLopHoc']);
		$DBuoiHoc = $BuoiHoc->LayDanhSach();
		$TietHoc = 0.0;
		$SoBuoi = 0;
		if($DBuoiHoc != null)
		{
			for($i = 0; $i < count($DBuoiHoc); $i++)
			{
				$TietHoc += (float)$DBuoiHoc[$i]['SoTietHoc'];
				$SoBuoi++;
			}
		}
		
		$DiemDanh = new diemdanh_bs();
		$DiemDanh->SetMaLopHoc($DLopHoc[0]['MaLopHoc']);
		$DDiemDanh = $DiemDanh->LayDanhSach();
		$SoLuotVang = 0;
		if($DDiemDanh != null)
		{
			for($i = 0; $i < count($DDiemDanh); $i++)
			{
				$SoLuotVang++;
			}
		}
		
		$HopDong = new hopdong_bs();
		$HopDong->SetMaLopHoc($DLopHoc[0]['MaLopHoc']);
		$HopDong->SetMaVaiTro('VG01'); //Là GV1
		$DHopDong = $HopDong->LayDanhSach();
		$GV1 = 'Chưa phân công';
		if($DHopDong != null)
		{
			$GiaoVien = new giaovien_bs();
			$GiaoVien->SetMaGiaoVien($DHopDong[0]['MaGiaoVien']);
			$DGiaoVien = $GiaoVien->LayDanhSach();
			$GV1 = $DGiaoVien == null ? 'N/A' : $DGiaoVien[0]['HoTen'];
		}
		
		$HopDong->SetMaVaiTro('VG02'); //Là GV1
		$DHopDong = $HopDong->LayDanhSach();
		$GV2 = 'Chưa phân công';
		if($DHopDong != null)
		{
			$GV2 = '';
			for($i = 0; $i < count($DHopDong); $i++)
			{
				$GiaoVien = new giaovien_bs();
				$GiaoVien->SetMaGiaoVien($DHopDong[0]['MaGiaoVien']);
				$DGiaoVien = $GiaoVien->LayDanhSach();
				$GV2 = ($i > 0 ? ', ' : '') . $DGiaoVien[0]['HoTen'];
			}
		}
		
		$HocVien = new hocvien_bs();
		$HocVien->SetMaLopHoc($DLopHoc[0]['MaLopHoc']);
		$DHocVien = $HocVien->LayDanhSach();
		$SLHocVien = $DHocVien == null ? 0 : count($DHocVien);
?>
<div class="FormCapNhat">
	<div class="Title">
		Thông tin chi tiết lớp học - <b><?php echo $DLopHoc[0]['MaLopHoc']; ?></b>
		<div style="float:right">
			<a href="index.php?act=lophoc_capnhat&mlh=<?php echo $DLopHoc[0]['MaLopHoc']; ?>&pin=<?php echo $DLopHoc[0]['PIN']; ?>">Cập nhật</a>
		</div>
	</div>
	
	<div class="Left">
		<table width="100%">
			<tr>
				<th colspan="2">Sắp xếp</th>
			</tr>
			<tr>
				<td width="20%">Khóa học</td>
				<td><input name="MaHocVien" type="text" style="font-weight:bold" readonly="true" value="<?php echo $TenKhoa; ?>"/></td>
			</tr>
			<tr>
				<td>Phòng học</td>
				<td><input readonly="true" name="HoTen" type="text" value="<?php echo $TenPhong; ?>"/></td>
			</tr>
			<tr>
				<td>Chương trình</td>
				<td><input readonly="true" name="NgaySinh" type="text" value="<?php echo $TenChuongTrinh; ?>"/></td>
			</tr>
			<tr>
				<td>Thời gian học</td>
				<td><input readonly="true" name="DiaChi" type="text" value="<?php echo $TenThoiGian; ?>"/></td>
			</tr>
			
		</table>
		<table width="100%">
			<tr>
				<th colspan="2">Hoạt động</th>
			</tr>
			<tr>
				<td width="20%">Tiết đã học</td>
				<td><input name="MaHocVien" type="text" readonly="true" value="<?php echo '~ ' . round($TietHoc) . '/' . $DChuongTrinhHoc[0]['SoTiet'] . ' tiết'; ?>"/></td>
			</tr>
			<tr>
				<td>Buổi học</td>
				<td><input readonly="true" name="HoTen" type="text" value="<?php echo $SoBuoi; ?>"/></td>
			</tr>
			<tr>
				<td>Lượt vắng</td>
				<td><input readonly="true" name="NgaySinh" type="text" id="datepicker" value="<?php echo $SoLuotVang; ?>"/></td>
			</tr>
		</table>
	</div>
	<div class="Right">
		
		<table width="100%">
			<tr>
				<th colspan="2">Tổ chức</th>
			</tr>
			<tr>
				<td width="35%">Giáo viên 1</td>
				<td>
					<input type="text" readonly="true" value="<?php echo $GV1; ?>" />
				</td>
			</tr>
			<tr>
				<td width="35%">Giáo viên 2</td>
				<td>
					<input type="text" readonly="true" value="<?php echo $GV2; ?>" />
				</td>
			</tr>
			<tr>
				<td width="35%">SL Học viên</td>
				<td>
					<input type="text" readonly="true" value="<?php echo $SLHocVien; ?>" />
				</td>
			</tr>
		</table>
	</div>
	<div width="100%" class="Bottom">
		<a href="#result" id="ToggleList">Xem DS học viên của lớp</a>
	</div>
	<div class="Bottom" id="result" hidden="true"></div>
</div>

<?php
	}
?>

<script type="text/javascript">
	var malop = '<?php echo $MaLopHoc; ?>';
	$(document).ready(function() {
		loadXMLHocVienDanhSachLop(malop);
	});
	$('#ToggleList').click(function() {
		$('#result').toggle();
	});
</script>